package servicos;

import java.util.List;

import dominio.Item;
import dominio.Orcamento;
import persistencia.OrcamentoDAO;
import persistencia.OrcamentoDAOImpl;
import persistencia.base.DAOException;
import persistencia.base.DAOFactory;

public class OrcamentoRN {

	private OrcamentoDAO orcamentoDAO = DAOFactory.getOrcamentoDAO();
	private OrcamentoDAOImpl orcamentoDAOImpl = new OrcamentoDAOImpl();
	
	public void salvar(Orcamento orcamento) throws FalhaDeInclusaoException {

		try {

			orcamentoDAO.getSession().beginTransaction();
			orcamentoDAO.save(orcamento);
			orcamentoDAO.getSession().getTransaction().commit();

		} catch (DAOException e) {
			e.printStackTrace();
			throw new FalhaDeInclusaoException();
		}
	}

	public List<Orcamento> listar() throws FalhaDeInclusaoException {

		try {
			return orcamentoDAO.findAll();

		} catch (DAOException e) {
			e.printStackTrace();
			throw new FalhaDeInclusaoException();
		}
	}

	public void deletar(Orcamento orcamento) throws FalhaDeDeletarExcepiton {
		try {
			orcamentoDAO.getSession().beginTransaction();
			orcamentoDAO.delete(orcamento);
			orcamentoDAO.getSession().getTransaction().commit();

		} catch (DAOException e) {
			e.printStackTrace();
			throw new FalhaDeDeletarExcepiton();
		}

	}

	public Integer verificaId() {

		return orcamentoDAOImpl.verificaId();

	}

	public List<Item> buscaItens(int id){
		
		return orcamentoDAOImpl.buscaItens(id);  
	}

}
